const state = {
	activities: [],
	activityTotal: 0,
	displayActivity: {},
	processingActivities: []
}
const mutations = {
	SET_ACTIVITIES(state, data) {
		state.activities = data.activities;
		state.activityTotal = data.total;
	},
	SET_DISPLAYACTIVITY(state, data) {
		state.displayActivity = data;
	},
	SET_PROCESSINGACTIVITIES(state, data) {
		state.processingActivities = data;
	},
}

const actions = {
	async getActivities({ commit }, data) {
		let response = await uni.$u.http.post('/activity/info', { ...data, needInforms: true });
		// console.log(response)
		let { code } = response.data
		if (code === 200) {
			commit('SET_ACTIVITIES', response.data.data);
		}
		return code;
	},
	async getActivitiesHistory({commit},data){
		let response = await uni.$u.http.post('/activity/info/history', { ...data});
		let { code } = response.data
		if (code === 200) {
			commit('SET_ACTIVITIES', response.data.data);
		}
		return code;
	},
	async joinActivity(_, data) {
		let result = await uni.$u.http.get('/activity/join', { params: { ...data } });
		let { code } = result.data;
		return code;
	},
	async getProcessiongActivities({ commit }, data) {
		let result = await uni.$u.http.post('/activity/info/processing', { ...data });
		if (result.data.code === 200) {
			commit('SET_PROCESSINGACTIVITIES', result.data.activities)
		}
	},
	async signin({ commit }, data) {
		let result = await uni.$u.http.get('/activity/signin', { params: { ...data } });
		return result.data.code;
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
